package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Gift;
import com.ruoyi.system.service.IGiftService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 礼物Controller
 * 
 * @author kinglu
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/Gift")
public class GiftController extends BaseController
{
    @Autowired
    private IGiftService giftService;

    /**
     * 查询礼物列表
     */
    @RequiresPermissions("system:Gift:list")
    @GetMapping("/list")
    public TableDataInfo list(Gift gift)
    {
        startPage();
        List<Gift> list = giftService.selectGiftList(gift);
        return getDataTable(list);
    }

    /**
     * 导出礼物列表
     */
    @RequiresPermissions("system:Gift:export")
    @Log(title = "礼物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gift gift)
    {
        List<Gift> list = giftService.selectGiftList(gift);
        ExcelUtil<Gift> util = new ExcelUtil<Gift>(Gift.class);
        util.exportExcel(response, list, "礼物数据");
    }

    /**
     * 获取礼物详细信息
     */
    @RequiresPermissions("system:Gift:query")
    @GetMapping(value = "/{giftId}")
    public AjaxResult getInfo(@PathVariable("giftId") Long giftId)
    {
        return AjaxResult.success(giftService.selectGiftByGiftId(giftId));
    }

    /**
     * 新增礼物
     */
    @RequiresPermissions("system:Gift:add")
    @Log(title = "礼物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gift gift)
    {
        return toAjax(giftService.insertGift(gift));
    }

    /**
     * 修改礼物
     */
    @RequiresPermissions("system:Gift:edit")
    @Log(title = "礼物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gift gift)
    {
        return toAjax(giftService.updateGift(gift));
    }

    /**
     * 删除礼物
     */
    @RequiresPermissions("system:Gift:remove")
    @Log(title = "礼物", businessType = BusinessType.DELETE)
	@DeleteMapping("/{giftIds}")
    public AjaxResult remove(@PathVariable Long[] giftIds)
    {
        return toAjax(giftService.deleteGiftByGiftIds(giftIds));
    }
}
